function openUploadModal(articleId) {
    document.getElementById('uploadModal').style.display = 'block';
    document.getElementById('uploadForm').setAttribute('action', '/carbon/upload/' + articleId);
}

// 关闭上传模态框
function closeUploadModal() {
    document.getElementById('uploadModal').style.display = 'none';
}

// 上传文件
function uploadFile() {
    const form = document.getElementById('uploadForm');
    const formData = new FormData(form);
    const fileInput = document.getElementById('fileInput');

    if(!fileInput.files[0]) {
        alert('请选择文件！');
        return;
    }
    fetch(form.action, {
        method: 'POST',
        body: formData
    })
        .then(response => {
            if (response.ok) {
                return response.text();
            } else {
                alert('文件上传失败！');
            }
        })
        .then(data => {
            // 处理返回的数据
            alert(data);
        })
        .catch(error => {
            console.error('上传错误:', error);
            alert('文件上传失败！');
        })
        .finally(() => {
            closeUploadModal();
            fileInput.value = ''; // 清空文件输入框
        });
}